package org.dromara.bzIns.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bzIns.domain.vo.CarIconVo;
import org.dromara.bzIns.domain.bo.CarIconBo;
import org.dromara.bzIns.service.ICarIconService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 汽车图标
 *
 * @author bz_huaYal9146
 * @date 2025-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/bzIns/carIcon")
public class CarIconController extends BaseController {

    private final ICarIconService carIconService;

    /**
     * 查询汽车图标列表
     */
    @SaCheckPermission("bzIns:carIcon:list")
    @GetMapping("/list")
    public TableDataInfo<CarIconVo> list(CarIconBo bo, PageQuery pageQuery) {
        return carIconService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出汽车图标列表
     */
    @SaCheckPermission("bzIns:carIcon:export")
    @Log(title = "汽车图标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CarIconBo bo, HttpServletResponse response) {
        List<CarIconVo> list = carIconService.queryList(bo);
        ExcelUtil.exportExcel(list, "汽车图标", CarIconVo.class, response);
    }

    /**
     * 获取汽车图标详细信息
     *
     * @param carIconId 主键
     */
    @SaCheckPermission("bzIns:carIcon:query")
    @GetMapping("/{carIconId}")
    public R<CarIconVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long carIconId) {
        return R.ok(carIconService.queryById(carIconId));
    }

    /**
     * 新增汽车图标
     */
    @SaCheckPermission("bzIns:carIcon:add")
    @Log(title = "汽车图标", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CarIconBo bo) {
        return toAjax(carIconService.insertByBo(bo));
    }

    /**
     * 修改汽车图标
     */
    @SaCheckPermission("bzIns:carIcon:edit")
    @Log(title = "汽车图标", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CarIconBo bo) {
        return toAjax(carIconService.updateByBo(bo));
    }

    /**
     * 删除汽车图标
     *
     * @param carIconIds 主键串
     */
    @SaCheckPermission("bzIns:carIcon:remove")
    @Log(title = "汽车图标", businessType = BusinessType.DELETE)
    @DeleteMapping("/{carIconIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] carIconIds) {
        return toAjax(carIconService.deleteWithValidByIds(List.of(carIconIds), true));
    }
}
